<template>
	<view class="searchBox">
		<view class="header" :style="'padding-top:'+barHeight+'px'">
			<u-icon name="arrow-left" color="#333" size="24" @click="back"></u-icon>
			<view class="inputBox">
				<input type="text" placeholder="请输入搜索关键词" v-model="name" class="keyword">
			</view>
			<view class="btn" @click="reload">搜索</view>
		</view>
		<scroll-view scroll-y="true" class="lists" @scrolltolower="lower()">
			<template v-if="type === 0">
				<view class="list" v-for="(item,index) of list" :key="index" @click="detail(item.id)">
					<image :src="oss(item.images)" class="cover" mode=""></image>
					<view class="info">
						<view class="title">
							<view class="l">{{item.name}}</view>
							<view class="r">
								<u-icon name="map-fill" size="20" color="#428DFC"></u-icon>{{item.juli.toFixed(1)}}km
							</view>
						</view>
						<view class="address">{{item.address}}</view>
						<view class="num">
							<view class="l">所需人数: {{item.num}}人</view>
							<view class="r"><text class="icon">¥</text>{{item.price}}</view>
						</view>
					</view>
				</view>
			</template>
			<template v-else-if="type === 2">
				<view class="list2" v-for="(item,index) of list" :key="index" @click="detail(item.user_id)">
					<image :src="oss(item.avatar)" class="cover" mode=""></image>
					<view class="info">
						<view class="title">
							<view class="l">{{item.nickname}}</view>
							<view class="r">
								<u-icon name="map-fill" size="20" color="#428DFC"></u-icon>{{item.juli.toFixed(1)}}km
							</view>
						</view>
						<view class="address">年龄：{{item.age}}</view>
						<view class="num">
							<view class="l"><text class="type">服务项目</text>
								<view class="word">{{item.name}}</view>
							</view>
							<view class="r"><text class="icon">¥</text>{{item.price}}</view>
						</view>
					</view>
					<view class="vip">
						<image src="../../static/serve/vip.png" mode="" class="icon"></image>
						<view class="word">推荐</view>
					</view>
				</view>
			</template>
			<template v-else-if="type === 1">
				<view class="list1" v-for="(item,index) of list" :key="index" @click="detail(item.id)">
					<image :src="oss(item.avatar)" class="cover" mode=""></image>
					<view class="info">
						<view class="title">
							<view class="l">{{item.name}}</view>
						</view>
						<view class="types">
							<view class="btn">{{item.catename}}</view>
							<view class="btn btn1">{{item.platform}}</view>
						</view>
						<view class="numBox">
							<u-line-progress :percentage="item.acceptnum/item.num" height="4" :showText="false"
								activeColor="#FFC141">
							</u-line-progress>
							<view class="num"><text class="word">{{item.acceptnum}}</text>/{{item.num}}</view>
						</view>
					</view>
					<view class="moeny">佣金{{item.price}}元</view>
					<!-- <view class="vip" v-if="item.istop > 0">
						<image src="../../static/serve/vip.png" mode="" class="icon"></image>
						<view class="word">置顶</view>
					</view> -->
				</view>
			</template>
			<u-empty v-if="finish && list.length === 0" :marginTop="200">
			</u-empty>
		</scroll-view>
	</view>
</template>

<script>
	let QQMapWX = require('../../common/qqmap-wx-jssdk.min.js');
	export default {
		data() {
			return {
				type: '',
				page: 1,
				finish: false,
				list: [],
				longitude: '',
				latitude: '',
				name: '',
				barHeight: '',
				equiptype: 0,
				city: ''
			};
		},
		onLoad(options) {
			this.barHeight = uni.getSystemInfoSync().statusBarHeight
			this.equiptype = uni.getSystemInfoSync().platform == 'ios' ? 2 : 1
			this.type = Number(options.type)
			let that = this
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					console.log(res)
					that.longitude = res.longitude
					that.latitude = res.latitude
					var qqmapsdk = new QQMapWX({
						key: 'LNWBZ-4DTKU-JQCVV-23LKL-4GM2V-2RBQI' // 必填
					});
					qqmapsdk.reverseGeocoder({
						location: '',
						success: function(res) {
							that.city = res.result.address_component.city
						}
					})
				}
			});
		},
		methods: {
			detail(id) {
				if (this.type === 0) {
					uni.$u.route({
						url: 'pagesA/index/detail',
						params: {
							id: id
						}
					})
				} else if (this.type === 1) {
					uni.$u.route({
						url: 'pages/task/detail',
						params: {
							id: id
						}
					})
				} else if (this.type === 2) {
					uni.$u.route({
						url: 'pages/serve/detail',
						params: {
							id: id
						}
					})
				}
			},
			lower() {
				this.page++
				this.getList()
			},
			reload() {
				this.finish = false
				this.page = 1
				this.list = []
				this.getList()
			},
			getList() {
				if (this.finish) {
					return
				}
				let data = {
					city: this.city,
					lng: this.longitude,
					lat: this.latitude,
					page: this.page,
					name: this.name,
					type: this.type,
					equiptype: this.equiptype
				}
				// uni.showModal({
				// 	title: '提示',
				// 	content: JSON.stringify(data),
				// 	success: function (res) {
				// 		if (res.confirm) {
				// 			console.log('用户点击确定');
				// 		} else if (res.cancel) {
				// 			console.log('用户点击取消');
				// 		}
				// 	}
				// });
				uni.$u.http.post('/search', {
					city: this.city,
					lng: this.longitude,
					lat: this.latitude,
					page: this.page,
					name: this.name,
					type: this.type,
					equiptype: this.equiptype
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {

				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	.searchBox {
		.header {
			display: flex;
			align-items: center;
			height: 88rpx;
			padding: 0 20rpx;
			background: linear-gradient(to left, #FFC141, #FFDF41);
			/* #ifdef MP-WEIXIN */
			padding-right: 220rpx;

			/* #endif */
			.inputBox {
				flex: 1;
				padding: 0 20rpx;
				background: #fff;
				border-radius: 40rpx;
				height: 70rpx;
				display: flex;
				align-items: center;

				.keyword {
					width: 100%;
					height: 60rpx;
					line-height: 60rpx;
				}
			}

			.btn {
				margin-left: 20rpx;
				font-weight: bold;
				font-size: 28rpx;
			}
		}

		.lists {
			.list {
				display: flex;
				margin: 10rpx 20rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;

				.cover {
					width: 180rpx;
					height: 180rpx;
					margin-right: 20rpx;
					flex-direction: 0;
					border-radius: 10rpx;
					flex-shrink: 0;
				}

				.address {
					font-size: 25rpx;
					color: #575859;
					height: 90rpx;
				}

				.info {
					flex: 1;

					.title {
						display: flex;
						align-items: center;

						.l {
							flex: 1;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}

						.r {
							color: #428DFC;
							font-size: 24rpx;
							flex-shrink: 0;
							display: flex;
							align-items: center;
						}
					}

					.num {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.l {
							background-color: #FFFAE5;
							height: 36rpx;
							border-radius: 18rpx;
							color: #FF8007;
							font-size: 20rpx;
							padding: 0 20rpx;
							display: flex;
							align-items: center;
						}

						.r {
							color: #FF5B1A;
							font-size: 40rpx;

							.icon {
								font-size: 28rpx;
							}
						}
					}
				}
			}

			.list2 {
				display: flex;
				margin: 10rpx 20rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;
				position: relative;

				.cover {
					width: 170rpx;
					height: 170rpx;
					margin-right: 20rpx;
					flex-direction: 0;
					border-radius: 10rpx;
					flex-shrink: 0;
				}

				.address {
					font-size: 25rpx;
					color: #575859;
					margin: 10rpx 0 20rpx;
				}

				.vip {
					position: absolute;
					left: 0;
					top: 40rpx;
					width: 74rpx;
					height: 44rpx;

					.icon {
						width: 74rpx;
						height: 44rpx;
					}

					.word {
						width: 74rpx;
						height: 44rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						color: #191615;
						font-size: 20rpx;
						position: absolute;
						left: 0;
						top: -10rpx;
						font-weight: bold;
					}
				}

				.info {
					flex: 1;

					.title {
						display: flex;
						align-items: center;

						.l {
							flex: 1;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}

						.r {
							color: #428DFC;
							font-size: 24rpx;
							flex-shrink: 0;
							display: flex;
							align-items: center;
						}
					}

					.num {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.l {
							display: flex;
							align-items: center;

							.type {
								color: #999999;
								font-size: 24rpx;
							}

							.word {
								background-color: #FFFAE5;
								height: 36rpx;
								border-radius: 18rpx;
								color: #FF8007;
								font-size: 20rpx;
								padding: 0 20rpx;
								display: flex;
								align-items: center;
							}
						}

						.r {
							color: #FF5B1A;
							font-size: 40rpx;

							.icon {
								font-size: 28rpx;
							}
						}
					}
				}
			}

			.list1 {
				display: flex;
				margin: 10rpx 20rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;
				align-items: center;
				position: relative;

				.vip {
					position: absolute;
					left: 0;
					top: 40rpx;
					width: 74rpx;
					height: 44rpx;

					.icon {
						width: 74rpx;
						height: 44rpx;
					}

					.word {
						width: 74rpx;
						height: 44rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						color: #191615;
						font-size: 20rpx;
						position: absolute;
						left: 0;
						top: -10rpx;
						font-weight: bold;
					}
				}

				.cover {
					width: 140rpx;
					height: 140rpx;
					margin-right: 20rpx;
					flex-direction: 0;
					border-radius: 10rpx;
					flex-shrink: 0;
				}

				.address {
					font-size: 25rpx;
					color: #575859;
				}

				.moeny {
					font-size: 30rpx;
					color: #FF5B1A;
					margin-left: 40rpx;
				}

				.info {
					flex: 1;

					.title {
						display: flex;
						align-items: center;

						.l {
							flex: 1;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}

						.r {
							color: #428DFC;
							font-size: 24rpx;
							flex-shrink: 0;
							display: flex;
							align-items: center;
						}
					}

					.types {
						display: flex;
						align-items: center;
						margin: 20rpx 0;

						.btn {
							background: #FFFAE5;
							height: 36rpx;
							border-radius: 18rpx;
							padding: 0 10rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							color: #FF8007;
							font-size: 24rpx;
							margin-right: 10rpx;
						}

						.btn1 {
							background-color: #E9F3FF;
							color: #428DFC;
						}
					}

					.numBox {
						display: flex;
						align-items: center;

						.num {
							display: flex;
							align-items: center;
							font-size: 22rpx;
							margin-left: 10rpx;

							.word {
								color: #428DFC;
							}
						}
					}
				}
			}

		}
	}
</style>
